home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 524 / 524.xpi / chrome / mid.jar / content / midGTransOverlay.js < prev    next >
Text File  |  2009-09-16  |  3KB  |  104 lines

  1.  
  2. generalPrefs = Components.classes["@mozilla.org/preferences-service;1"]
  3.         .getService(Components.interfaces.nsIPrefBranch);
  4.  
  5.  
  6. window.addEventListener("load", googTransInit, false);
  7.  
  8. var selection = '';
  9. var trans = '';
  10.  
  11.  
  12.  
  13. function googTransInit() {
  14.     var ifrdoc = document.getElementById("mid_google_iframe").contentDocument;
  15.     if (this.notFirst) {
  16.          return;
  17.     }
  18.     var currentLocale = generalPrefs.getCharPref("general.useragent.locale");
  19.     document.getElementById("mid_mainbrowsercontextpopup").addEventListener("popupshowing", ongoogTransPopup, false);
  20.     this.notFirst = true;
  21.     // completely moron idea to set the source to the locale:
  22.     // document.getElementById("mid_google_iframe").contentDocument.getElementById('src').value=currentLocale; hu in win hu_HU in Linux
  23.     ifrdoc.getElementById("google_translate").value  = mid_mud.util.getLocaleString("translate");
  24.     ifrdoc.getElementById("results_title").innerHTML = mid_mud.util.getLocaleString("translation");
  25. }
  26.  
  27.  
  28.  
  29. function ongoogTransPopup(event) {    
  30.  
  31.     if (event.target.id != 'mid_mainbrowsercontextpopup') return;
  32.  
  33.     var popupnode = document.popupNode;
  34.     var nodeLocalName = popupnode.localName.toLowerCase();
  35.  
  36.     if ((nodeLocalName == "textarea") || (nodeLocalName == "input" && popupnode.type == "text")) {
  37.         selection = trim(popupnode.value.substring(popupnode.selectionStart, popupnode.selectionEnd));
  38.     } else {
  39.         if (nodeLocalName == "img") {
  40.             if (popupnode.title)
  41.                 selection = popupnode.title;
  42.            else if (popupnode.alt)
  43.                 selection = popupnode.alt;
  44.            else
  45.                selection = '';
  46.         } else {
  47.             var focusedWindow = document.commandDispatcher.focusedWindow;
  48.             selection = trim(focusedWindow.getSelection().toString());
  49.         }
  50.     } 
  51.     if (selection != '') {
  52.         document.getElementById("translate_main").disabled = false;
  53.     } else {
  54.         document.getElementById("translate_main").disabled = true;
  55.     }
  56.  
  57. }
  58.  
  59.  
  60.  
  61. function mid_googleTranslate() {
  62.  
  63.     var ifrdoc = document.getElementById("mid_google_iframe").contentDocument;
  64.     if (selection != '') {
  65.           ifrdoc.getElementById("source").value = selection; 
  66.         ifrdoc.forms[0].onsubmit();   
  67.     } else return;
  68.  
  69.     var  viewitem = document.getElementById("mid_viewpopupgoogletranslatoritem"); 
  70.     if ( viewitem.getAttribute("checked") == "false" ) {
  71.          viewitem.doCommand();
  72.     }
  73. }
  74.  
  75.  
  76.     
  77. function googleTranslateView() {
  78.  
  79.     var gtSplitter = document.getElementById("mid_editor_splitter");
  80.     var gt = document.getElementById("mid_google_iframe");
  81.     if (gt.getAttribute("collapsed") == "true") {
  82.         document.getElementById("mid_viewpopupgoogletranslatoritem").setAttribute("checked", "true");
  83.         gt.setAttribute("collapsed", "false");
  84.         gtSplitter.setAttribute("collapsed", "false");
  85.     } else {
  86.         document.getElementById("mid_viewpopupgoogletranslatoritem").setAttribute("checked", "false");
  87.         gt.setAttribute("collapsed", "true");
  88.         gtSplitter.setAttribute("collapsed", "true");
  89.     }
  90.     mid_mud.layoutManager.checkSideBar();
  91. }
  92.  
  93.  
  94.  
  95. function trim(str) {
  96.     var x = str;
  97.     x = x.replace(/^\s*(.*)/, "$1");
  98.     x = x.replace(/(.*?)\s*$/, "$1");
  99.     return x;
  100. }
  101.  
  102.  
  103.  
  104.